package com.wei.lolbox.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.wei.lolbox.model.discover.HeroRoles;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "HERO_ROLES".
*/
public class HeroRolesDao extends AbstractDao<HeroRoles, Long> {

    public static final String TABLENAME = "HERO_ROLES";

    /**
     * Properties of entity HeroRoles.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Role_in_cn = new Property(1, String.class, "role_in_cn", false, "ROLE_IN_CN");
        public final static Property Name = new Property(2, String.class, "name", false, "NAME");
        public final static Property Role = new Property(3, String.class, "role", false, "ROLE");
        public final static Property Desc = new Property(4, String.class, "desc", false, "DESC");
    }

    private Query<HeroRoles> heroes_RolesQuery;

    public HeroRolesDao(DaoConfig config) {
        super(config);
    }
    
    public HeroRolesDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"HERO_ROLES\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: id
                "\"ROLE_IN_CN\" TEXT," + // 1: role_in_cn
                "\"NAME\" TEXT NOT NULL ," + // 2: name
                "\"ROLE\" TEXT," + // 3: role
                "\"DESC\" TEXT);"); // 4: desc
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"HERO_ROLES\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, HeroRoles entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String role_in_cn = entity.getRole_in_cn();
        if (role_in_cn != null) {
            stmt.bindString(2, role_in_cn);
        }
        stmt.bindString(3, entity.getName());
 
        String role = entity.getRole();
        if (role != null) {
            stmt.bindString(4, role);
        }
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(5, desc);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, HeroRoles entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String role_in_cn = entity.getRole_in_cn();
        if (role_in_cn != null) {
            stmt.bindString(2, role_in_cn);
        }
        stmt.bindString(3, entity.getName());
 
        String role = entity.getRole();
        if (role != null) {
            stmt.bindString(4, role);
        }
 
        String desc = entity.getDesc();
        if (desc != null) {
            stmt.bindString(5, desc);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public HeroRoles readEntity(Cursor cursor, int offset) {
        HeroRoles entity = new HeroRoles( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // role_in_cn
            cursor.getString(offset + 2), // name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // role
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4) // desc
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, HeroRoles entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setRole_in_cn(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setName(cursor.getString(offset + 2));
        entity.setRole(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setDesc(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(HeroRoles entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(HeroRoles entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(HeroRoles entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "roles" to-many relationship of Heroes. */
    public List<HeroRoles> _queryHeroes_Roles(String name) {
        synchronized (this) {
            if (heroes_RolesQuery == null) {
                QueryBuilder<HeroRoles> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Name.eq(null));
                heroes_RolesQuery = queryBuilder.build();
            }
        }
        Query<HeroRoles> query = heroes_RolesQuery.forCurrentThread();
        query.setParameter(0, name);
        return query.list();
    }

}
